import pygame, sys
import pygame.color
import pygame.colordict
import pygame.draw
import pygame.mouse
import pygame.sprite
import pygame.time
import pygame.display
import pygame.event
import pygame.key

from event import *
from entity import *

pygame.init()

class Main:
    screen = pygame.display.set_mode((1920, 1080))
    clock = pygame.time.Clock()
    player = Entity(Vec3(0, 0, 0))

    def init():
        EventBus.register(BasicEvent)
        EventBus.register(TickEvent)
        EventBus.register(KeyPressedEvent)
        EventBus.register(KeyReleasedEvent)

    @classmethod
    def main(cls):
        while True:
            cls.clock.tick(20)
            
            for e in pygame.event.get():
                if e.type == pygame.QUIT:
                    cls.stop()
            
                elif e.type == pygame.KEYDOWN:
                    EventBus.post(KeyPressedEvent(e.key))
                elif e.type == pygame.KEYUP:
                    EventBus.post(KeyReleasedEvent(e.key))
            
            EventBus.post(TickEvent())
            
            EventBus.execute()

    @classmethod
    def render(cls):
        while True:
            cls.clock.tick(60)

            cls.screen.fill("black")
            pygame.draw.polygon(cls.screen, "green", cls.player.obb.get_corners(), 2)
            pygame.display.flip()

    @classmethod
    def stop(cls):
        pygame.quit()
        sys.exit()